<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		
		<view class="group-btn">
			<button type="primary" @click="commRouterTap('/pages/deviceList/deviceList')">路由拦截</button>
			<button @click="setToken">设置TOKEN</button>
			<button type="warn" @click="removeToken">删除TOKEN</button>
		</view>

		<view>路由跳转方式：</view>
		<view class="group-btn">
			<button type="primary" @click="routerMethodTap(1)">字符串</button>
			<button type="primary" @click="routerMethodTap(2)">对象</button>
			<button type="primary" @click="routerMethodTap(3)">命名路由</button>
			<button type="primary" @click="routerMethodTap(4)">url传参</button>
		</view>
		
		<button type="warn" @click="commRouterTap('/pages/user/user')">404</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {

		},
		methods: {
			commRouterTap(url) {
				uni.navigateTo({
					url
				})
			},
			setToken() {
				uni.setStorageSync('token', '123456')
			},
			removeToken() {
				uni.removeStorageSync('token')
			},
			routerMethodTap(type) {
				switch (type) {
					case 1:
						// 字符串
						this.$Router.push('/pages/login/login');
						break;
					case 2:
						// 对象
						this.$Router.push({
							path: '/pages/login/login'
						})
						break;
					case 3:
						// 命名的路由
						this.$Router.push({
							name: 'login',
							params: {
								name: '小不点~'
							}
						})
						break;
					case 4:
						// 带查询参数，变成 /pages/login/login?name=smile
						this.$Router.push({
							path: '/pages/login/login',
							query: {
								name: 'smile'
							}
						})
						break;
				}
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.group-btn {
		width: 100%;
		margin: 30rpx 0;
		display: flex;
		justify-content: space-around;
	}
</style>